WSL (Ubuntu)の初期設定手順
最初の画面
code:sh
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username:
このあとusernameとpasswordを入力すればおしまい
ログ全文
IP addressとかは消してある
code:bash
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: takker
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 4.4.0-19041-Microsoft x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Fri Oct 1 12:49:38 JST 2021
System load: 0.52
Usage of /home: unknown
Memory usage: 52%
Swap usage: 1%
Processes: 7
Users logged in: 0
IPv4 address for eth1:
IPv4 address for wifi0:
IPv6 address for wifi0:
IPv6 address for wifi0:
1 update can be applied immediately.
To see these additional updates run: apt list --upgradable
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
This message is shown once a day. To disable it please create the
/home/takker/.hushlogin file.
$
このあとやること
1. Ubuntuのレポジトリサーバを日本国内のに変更
2. sudo apt update && sudo apt upgrade
3. Ubuntuを日本語化する
4. takker99/dotfilesをinstallするdirを作る
$ cd && mkdir git && cd git
5. GitHubで使うSSH鍵を生成
6. dotfilesをcloneする
$ git clone git@github.com:takker99/dotfiles.git
7. 必要なソフトを入れる
neovim
deno
yarn
rust
install rust
bat
exa
shell scriptでinstallも自動化したい……
shellでcommandの存在を判定する
shellで例外処理
code:bash
curl "https://scrapbox.io/api/code/takker/WSL_(Ubuntu)%E3%81%AE%E5%88%9D%E6%9C%9F%E8%A8%AD%E5%AE%9A%E6%89%8B%E9%A0%86/install.sh" > install.sh && source install.sh | rm install.sh
bashでは環境変数が反映されないので、source (shell)を代わりに使う
と思ったのだが、sourceの実行段階で謎のエラーが現れて実行できない……
どうすりゃええねんtakker.icon
code:install.sh
#!/bin/bash
set -eu
catch () {
echo "Some error have occurred. Terminate the installation."
}
trap catch ERR
if !(type "nvim" > /dev/null 2>&1); then
echo "neovim is not installed. Install neovim..."
sudo apt install neovim -y
echo "Successfully installed neovim."
fi
if !(type "batcat" > /dev/null 2>&1); then
echo "bat is not installed. Install bat..."
sudo apt install bat -y
echo "Successfully installed bat."
fi
# required to install deno
if !(type "unzip" > /dev/null 2>&1); then
echo "unzip is not installed. Install unzip..."
sudo apt install unzip -y
echo "Successfully installed unzip."
fi
export DENO_INSTALL="$HOME/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
if !(type "deno" > /dev/null 2>&1); then
echo "deno is not installed. Install deno..."
curl -fsSL https://deno.land/x/install/install.sh | sh
echo "Successfully installed deno."
fi
nvmのinstallとかはWSL 2 上で Node.jis を設定する | Microsoft Docs を参照
code:install.sh
# required to install npm
export NVM_DIR="$HOME/.nvm"
-s "$NVM_DIR/nvm.sh" && \. "$NVM_DIR/nvm.sh" # This loads nvm
-s "$NVM_DIR/bash_completion" && \. "$NVM_DIR/bash_completion" # This loads nvm
if !(type "nvm" > /dev/null 2>&1); then
echo "nvm is not installed. Install nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
echo "Successfully installed nvm."
fi
# required to install npm
if !(type "node" > /dev/null 2>&1); then
echo "Node.js is not installed. Install Node.js..."
nvm install node
template文字列をshellで使う方法
here documentも使っている
ファイルにかかれた変数をBashで展開し、Templateのように扱う - grep Tips *
bashのヒアドキュメントを活用する - Qiita
code:install.sh
eval "cat <<< \"current Node version: $(node --version)\""
eval "cat <<< \"current npm version: $(npm --version)\""
echo "Successfully installed node and npm."
fi
if !(type "yarn" > /dev/null 2>&1); then
echo "yarn is not installed. Install yarn..."
npm install -g yarn
# use yarn V2
yarn set version berry
echo "Successfully installed yarn."
fi
if !(type "cargo" > /dev/null 2>&1); then
echo "Rust compile tools is not installed. Install rustup and cargo..."
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
echo "Successfully installed rustup."
fi
source $HOME/.cargo/env
if !(type "cc" > /dev/null 2>&1); then
echo "C/C++ compiler is not installed. Install clang..."
sudo apt install clang -y
echo "Successfully installed clang."
fi
if !(type "exa" > /dev/null 2>&1); then
echo "exa is not installed. Install exa..."
cargo install exa
echo "Successfully installed exa."
fi
#WSL #Ubuntu
#2021-10-01 12:48:51